import 'package:domain/model/banner_domain_model.dart';
import 'package:domain/usecases/banner_use_case.dart';
import 'package:domain/usecases/home_article_use_case.dart';
import 'package:feature_main/ui/home_tab/viewmodel/home_tab_fragment_view_model.dart';
import 'package:feature_main/ui/home_tab/viewmodel/state_and_events.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockBannerUseCase extends Mock implements BannerUseCase {}

class MockArticleUseCase extends Mock implements HomeArticleUseCase {}

void testGroup() {
  group(HomeTabFragmentViewModel, () {
    late MockBannerUseCase bannerUseCase;
    late MockArticleUseCase articleUseCase;
    late HomeTabFragmentViewModel viewModel;

    setUp(() {
      bannerUseCase = MockBannerUseCase();
      articleUseCase = MockArticleUseCase();
      viewModel = HomeTabFragmentViewModel(
        bannerUseCase: bannerUseCase,
        articleUseCase: articleUseCase,
      );
      viewModel.onInit();
    });

    tearDown(() {
      viewModel.onClose();
      reset(bannerUseCase);
      reset(articleUseCase);
    });

    test('test init event', () async {
      final testBannerId = 'ss';
      final testBannerDesc = 'sssss';
      final testBannerTitle = 'ssfdfas';
      final testBannerImage = 'fdfdfdf';
      final testBannerUrl = 'fdsssfdfdf';
      when(() => bannerUseCase.fetchBanners()).thenAnswer(
        (_) async => [
          BannerDomainModel(
            id: testBannerId,
            desc: testBannerDesc,
            title: testBannerTitle,
            imageUrl: testBannerImage,
            url: testBannerUrl,
          ),
        ],
      );

      when(
        () => articleUseCase.fetchArticles(page: any(named: 'page')),
      ).thenAnswer((_) async => []);
      viewModel.sendEvent(HomeTabFragmentInitEvent());
      
      await Future.delayed(Duration.zero);
      final state = viewModel.state;
    });
  });
}

void main() {
  testGroup();
}
